package cn.fl.project.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.insroute.service.IInsRouteBscInfoService;
import cn.fl.insroute.vo.InsRouteBscInfoVO;
import cn.fl.insroute.vo.InsRoutePrdInfoVO;
import cn.fl.insroute.vo.InsRoutePrpsFeeVO;
import cn.fl.preloan.enums.LogBusinessTypeEnum;
import cn.fl.project.condition.PrjPrdBscInfoQueryCondition;
import cn.fl.project.condition.PrjQuatPrpsCfgDQueryCondition;
import cn.fl.project.condition.PrjQuatPrpsQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.constant.PrjQuatPrpsConstant;
import cn.fl.project.constant.PrjQuatPrpsFeeConstant;
import cn.fl.project.service.*;
import cn.fl.project.vo.*;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.lionbridge.log.ext.ExtSlf4jLogger;
import com.lionbridge.log.ext.ExtSlf4jLoggerBuilder;
import com.lionbridge.log.ext.LogTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 项目报价方案配置明细信息表 控制层
 */
@Slf4j
@Controller
@RequestMapping("/project/prjQuatPrpsCfgD")
public class PrjQuatPrpsCfgDController extends BaseController{
	private static ExtSlf4jLogger logger = ExtSlf4jLoggerBuilder.create()
			.setLogger(log).setBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setSubBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setLogType(LogTypeEnum.BUSINESS).build().setKeywords("PrjQuatPrpsCfgD");
	/**
	 * PrjQuatPrpsCfgD 服务层BEAN
	 */
	@Autowired
	private IPrjQuatPrpsCfgDService prjQuatPrpsCfgDService;

	@Autowired
	private IPrjQuatPrpsCfgMService prjQuatPrpsCfgMService;
	
	/**
	 * 数据字典本地服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	@Autowired
	private IInsRouteBscInfoService insRouteBscInfoService;

	@Autowired
	private IPrjBscInfoService prjBscInfoService;

	@Autowired
	private IPrjPrdBscInfoService prjPrdBscInfoService;

	@Autowired
	private IPrjQuatPrpsService prjQuatPrpsService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("project/prjQuatPrpsCfgD/list");
		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("project/prjQuatPrpsCfgD/modify");
		view.addObject("id", id);
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String prpsCfgId = request.getParameter("prpsCfgId");
		String prjId = request.getParameter("prjId");
		/*if(StringUtils.isEmpty(prpsCfgId)){//没有方案配置ID 直接返回null
			return null;
		}*/
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
		page.setEveryPage(Integer.MAX_VALUE);//最大数据量
		double totalPrdAmt=0d;
		if (StringUtils.isNotEmpty(prpsCfgId)) {	//如果有方案配置ID 直接查询此方案配置的相关费用信息
		    if(StringUtils.isNotBlank(prjId)){
                PrjBscInfoVO bscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
                PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
                if(StringUtils.isNotBlank(prjId)){
                    prdQc.setPrjId(Long.valueOf(prjId));
                    List<PrjPrdBscInfoVO> prdList=	this.prjPrdBscInfoService.searchList(prdQc);
                    if(CollectionUtils.isNotEmpty(prdList)){
                        for (PrjPrdBscInfoVO prjPrdBscInfoVO : prdList) {
                            totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
                        }
                    }
                }
            }
			PrjQuatPrpsCfgMVO quatPrps = this.prjQuatPrpsCfgMService.selectById(Long.valueOf(prpsCfgId));
			qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
			page.setCondition(qc);
	
			Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
			List<PrjQuatPrpsCfgDVO> list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_QUAT_FEE_TYP_CD);
			if(CollectionUtils.isNotEmpty(list)){
				for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
					String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();//费用类型代码 如果此费用类型在数据字典里是系统内置的 则设置flag标识
					for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
						String code = sysDictionaryDTO.getCode();
						if(code.equals(feeTypCd)){
							if(sysDictionaryDTO.getIsSysDef().equals(BaseConstant.IS_YESNO_YES)){
								prjQuatPrpsCfgDVO.setFlag(BaseConstant.IS_YESNO_YES);
								prjQuatPrpsCfgDVO.setFlagNm(BaseConstant.IS_YESNO_YES_NM);
							}
						}
					}
					//处理费用金额
					if(null!=prjQuatPrpsCfgDVO.getFixedAmt()){
						prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.div(prjQuatPrpsCfgDVO.getFixedAmt(), 100));
					}
				}
				if(StringUtils.isNotBlank(prjId)){
					PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
					String prjTypCd = prjBscInfoVO.getPrjTypCd();
					Integer isInsBiz = prjBscInfoVO.getIsInsBiz();
					if(!(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(CurrentThreadContext.getCurrentBuOrgCd()) && !(BaseConstant.IS_YESNO_YES == isInsBiz))){
						InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
						List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
						if(insRouteBscInfoVO != null){
							insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
						}
						List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
						Double mediationFeeAmtSum = 0d;
						if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
							for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
								mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());

							}
						}
						Double actAmt = 0d;
						boolean fee76 = false;
						for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
							String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
							if(StringUtils.isNotBlank(prjId) && PrjBscInfoConstant.CODE_BU_ORG_CD_QK.equals(CurrentThreadContext.getCurrentBuOrgCd())){
								quatPrps.setLsPd(36l);
								if(StringUtils.isNotEmpty(feeTypCd) && PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)){
									if (quatPrps.getPrpsCfgNm().contains("东风")) {
										List<SysDictionaryDTO>  dicLists =  this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(),PrjQuatPrpsConstant.CTRL_LCV_PRJ0160);
										for (SysDictionaryDTO sysDictionaryDTO : dicLists) {
											if (sysDictionaryDTO.getCode().equals(quatPrps.getLsPd().toString())){
												String cdes = sysDictionaryDTO.getCodeDesc();
												if(StringUtils.isNotBlank(cdes)){
													prjQuatPrpsCfgDVO.setFeePct(Double.valueOf(cdes));
													prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.mul(totalPrdAmt,Double.valueOf(cdes)/100,0)/100);
												}
											}
										}
									}else{
										prjQuatPrpsCfgDVO.setFeePct(15d);
										prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.mul(totalPrdAmt,0.15,0)/100);
									}
								}
							}
							if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
								fee76 = true;
								prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
								if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
									prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
									prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
									prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
								}else{
									prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
									prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
								}
								prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
								prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
							}
							if(StringUtils.isNotEmpty(feeTypCd)
									&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
									|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)
									|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(feeTypCd)
									|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_64.equals(feeTypCd))){
								if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
									for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
										if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
											actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
										}
									}
									for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
										if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
											if(null!=insRoutePrpsFeeVO.getFeeAmt()){
												prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.convertFenToYuan(insRoutePrpsFeeVO.getFeeAmt().longValue()));
											}
											if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
												prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
											}
											if(null!=insRoutePrpsFeeVO.getCntWayCd()){
												prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
											}
											if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
												prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
											}
											prjQuatPrpsCfgDVO.setIsRoute(BaseConstant.IS_YESNO_YES);
											if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
												if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
														&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
													if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
														if(null!=insRoutePrpsFeeVO.getFeeAmt()){
															prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
														}
													}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
														prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
													}
												}
											}
										}
									}
								}
							}
						}
						if(mediationFeeAmtSum != 0 && !fee76){
							PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
							prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
							prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
							prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
							prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
							prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
							prjQuatPrpsCfgDVO.setIsSysDefNm("否");
							prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
							if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
								prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
								prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
								prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
							}else{
								prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
								prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
							}
							prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
							prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
							list.add(prjQuatPrpsCfgDVO);
						}
					}
				}
			}
			ListPageVO<PrjQuatPrpsCfgDVO> listPage = new ListPageVO<PrjQuatPrpsCfgDVO>(list, pager.getTotalCount());
			logger.info("查询数据完成.page：{}",JSON.toJSONString(page));
			return listPage;
		}else{	//没有方案配置ID 说明是方案的新增页面 查询数据字典里的系统内置费用类型 封装成PrjQuatPrpsCfgDVO 传到页面
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_QUAT_FEE_TYP_CD);
			List<PrjQuatPrpsCfgDVO> list = new ArrayList<PrjQuatPrpsCfgDVO>();
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					if(BaseConstant.IS_YESNO_YES == sysDictionaryDTO.getIsSysDef() ){//数据字典系统内置
						PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
						prjQuatPrpsCfgDVO.setFeeTypCd(sysDictionaryDTO.getCode());
						prjQuatPrpsCfgDVO.setFeeTypCdNm(sysDictionaryDTO.getCodeNm());
						prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_YES);//是否系统内置
						prjQuatPrpsCfgDVO.setIsSysDefNm(BaseConstant.IS_YESNO_YES_NM);
						prjQuatPrpsCfgDVO.setIsDefVis(BaseConstant.IS_YESNO_YES);//是否缺省显示
						prjQuatPrpsCfgDVO.setIsDefVisNm(BaseConstant.IS_YESNO_YES_NM);
						prjQuatPrpsCfgDVO.setFlag(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setFlagNm(BaseConstant.IS_YESNO_YES_NM);
						//prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						//prjQuatPrpsCfgDVO.setIsFixedAmtNm(BaseConstant.IS_YESNO_YES_NM);
						list.add(prjQuatPrpsCfgDVO);
					}
				}
			}
			ListPageVO<PrjQuatPrpsCfgDVO> listPage = new ListPageVO<PrjQuatPrpsCfgDVO>(list, list.size());
			logger.info("查询数据完成. DATA:{}",JSON.toJSONString(page));
			return listPage;
		}
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initListForQk.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initListForQk(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String prpsCfgId = request.getParameter("prpsCfgId");
		String prjId = request.getParameter("prjId");
		String lsPd = request.getParameter("lsPd");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
		page.setEveryPage(Integer.MAX_VALUE);//最大数据量
		double totalPrdAmt=0d;
		if(StringUtils.isNotBlank(prjId)){
			PrjPrdBscInfoQueryCondition prdQc = new PrjPrdBscInfoQueryCondition();
			if(StringUtils.isNotBlank(prjId)){
				prdQc.setPrjId(Long.valueOf(prjId));
				List<PrjPrdBscInfoVO> prdList=	this.prjPrdBscInfoService.searchList(prdQc);
				if(CollectionUtils.isNotEmpty(prdList)){
					for (PrjPrdBscInfoVO prjPrdBscInfoVO : prdList) {
						totalPrdAmt += DecimalUtils.mul(prjPrdBscInfoVO.getGuidePc(), prjPrdBscInfoVO.getPrdQty());
					}
				}
			}
		}
		if (StringUtils.isEmpty(prpsCfgId)) {
			PrjQuatPrpsQueryCondition prjQuatPrpsQueryCondition = new PrjQuatPrpsQueryCondition();
			prjQuatPrpsQueryCondition.setPrjId(Long.valueOf(prjId));
			prjQuatPrpsQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
			List<PrjQuatPrpsVO> prjQuatPrpsVOS = this.prjQuatPrpsService.searchList(prjQuatPrpsQueryCondition);
			for (PrjQuatPrpsVO prjQuatPrpsVO : prjQuatPrpsVOS) {
				if(prjQuatPrpsVO.getPrpsCfgId() != null){
					prpsCfgId = prjQuatPrpsVO.getPrpsCfgId().toString();
				}
			}
		}
		PrjQuatPrpsCfgMVO quatPrps = this.prjQuatPrpsCfgMService.selectById(Long.valueOf(prpsCfgId));
		qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
		page.setCondition(qc);

		Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
		List<PrjQuatPrpsCfgDVO> list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
		List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_QUAT_FEE_TYP_CD);
		if(CollectionUtils.isNotEmpty(list)){
			for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
				String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();//费用类型代码 如果此费用类型在数据字典里是系统内置的 则设置flag标识
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					String code = sysDictionaryDTO.getCode();
					if(code.equals(feeTypCd)){
						if(sysDictionaryDTO.getIsSysDef().equals(BaseConstant.IS_YESNO_YES)){
							prjQuatPrpsCfgDVO.setFlag(BaseConstant.IS_YESNO_YES);
							prjQuatPrpsCfgDVO.setFlagNm(BaseConstant.IS_YESNO_YES_NM);
						}
					}
				}
				//处理费用金额
				if(null!=prjQuatPrpsCfgDVO.getFixedAmt()){
					prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.div(prjQuatPrpsCfgDVO.getFixedAmt(), 100));
				}
			}
			if(StringUtils.isNotBlank(prjId)){
				PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
				String prjTypCd = prjBscInfoVO.getPrjTypCd();
				Integer isInsBiz = prjBscInfoVO.getIsInsBiz();
				if(!(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(CurrentThreadContext.getCurrentBuOrgCd()) && !(BaseConstant.IS_YESNO_YES == isInsBiz))){
					InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
					List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
					if(insRouteBscInfoVO != null){
						insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
					}
					List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
					Double mediationFeeAmtSum = 0d;
					if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
						for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
							mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());

						}
					}
					Double actAmt = 0d;
					boolean fee76 = false;
					for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
						String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
						if(StringUtils.isNotBlank(prjId) && PrjBscInfoConstant.CODE_BU_ORG_CD_QK.equals(CurrentThreadContext.getCurrentBuOrgCd())){
							if(StringUtils.isNotBlank(lsPd)){
								quatPrps.setLsPd(Long.valueOf(lsPd));
							}else{
								quatPrps.setLsPd(36l);
							}
							if(StringUtils.isNotEmpty(feeTypCd) && PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)){
								if (quatPrps.getPrpsCfgNm().contains("东风")) {
									List<SysDictionaryDTO>  dicLists =  this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(),PrjQuatPrpsConstant.CTRL_LCV_PRJ0160);
									for (SysDictionaryDTO sysDictionaryDTO : dicLists) {
										if (sysDictionaryDTO.getCode().equals(quatPrps.getLsPd().toString())){
											String cdes = sysDictionaryDTO.getCodeDesc();
											if(StringUtils.isNotBlank(cdes)){
												prjQuatPrpsCfgDVO.setFeePct(Double.valueOf(cdes));
												prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.mul(totalPrdAmt,Double.valueOf(cdes)/100,0)/100);
											}
										}
									}
								}else{
									prjQuatPrpsCfgDVO.setFeePct(15d);
									prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.mul(totalPrdAmt,0.15,0)/100);
								}
							}
						}
						if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
							fee76 = true;
							prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
							if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
								prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
								prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
								prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
							}else{
								prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
								prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
							}
							prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
							prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
						}
						if(StringUtils.isNotEmpty(feeTypCd)
								&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
								|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)
								|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(feeTypCd)
								|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_64.equals(feeTypCd))){
							if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
								for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
									if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
										actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
									}
								}
								for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
									if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
										if(null!=insRoutePrpsFeeVO.getFeeAmt()){
											prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.convertFenToYuan(insRoutePrpsFeeVO.getFeeAmt().longValue()));
										}
										if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
											prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
										}
										if(null!=insRoutePrpsFeeVO.getCntWayCd()){
											prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
										}
										if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
											prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
										}
										prjQuatPrpsCfgDVO.setIsRoute(BaseConstant.IS_YESNO_YES);
										if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
											if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
													&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
												if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
													if(null!=insRoutePrpsFeeVO.getFeeAmt()){
														prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
													}
												}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
													prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
												}
											}
										}
									}
								}
							}
						}
					}
					if(mediationFeeAmtSum != 0 && !fee76){
						PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
						prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
						prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
						prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
						prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
						prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
						prjQuatPrpsCfgDVO.setIsSysDefNm("否");
						prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
						if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
							prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
						}else{
							prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
							prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
						}
						prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
						prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
						list.add(prjQuatPrpsCfgDVO);
					}
				}
			}
		}
		ListPageVO<PrjQuatPrpsCfgDVO> listPage = new ListPageVO<PrjQuatPrpsCfgDVO>(list, pager.getTotalCount());
		logger.info("查询数据完成. DATA:{}",JSON.toJSONString(page));
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.prjQuatPrpsCfgDService.removeById(Long.valueOf(id));
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		
		try {
			PrjQuatPrpsCfgDVO vo = this.prjQuatPrpsCfgDService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
			}
			result.setData(vo);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjQuatPrpsCfgDVO entity = null;
		try {
			entity = new PrjQuatPrpsCfgDVO();
			//TODO ADD PARAM
			Long id = this.prjQuatPrpsCfgDService.add(entity);
			result.setData(id);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		PrjQuatPrpsCfgDVO entity = null;
		try {
			entity = new PrjQuatPrpsCfgDVO();
			entity.setId(Long.valueOf(id));
			//entity.setName(name);
			//TODO ADD PARAM
			boolean success = this.prjQuatPrpsCfgDService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
		}
		return result;
	}
	
	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initPrjQuatPrpsCfgList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initPrjQuatPrpsCfgList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String prpsCfgId = request.getParameter("prpsCfgId");
		String prjId = request.getParameter("prjId");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		   PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
		    page.setEveryPage(Integer.MAX_VALUE);//最大数据量
			qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
			page.setCondition(qc);
			Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
			List<PrjQuatPrpsCfgDVO> list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
			List<PrjQuatPrpsCfgDVO> feeList =new ArrayList<PrjQuatPrpsCfgDVO>();
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_PRJ_QUAT_FEE_TYP_CD);
			if(CollectionUtils.isNotEmpty(list)){
				for (int i=0;i<list.size();i++) {
					PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO  = list.get(i);
					//处理费用金额
					if(null!=prjQuatPrpsCfgDVO.getFixedAmt()){
						prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.div(prjQuatPrpsCfgDVO.getFixedAmt(), 100));
					}
					if(!prjQuatPrpsCfgDVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT)){
						feeList.add(prjQuatPrpsCfgDVO);
					}
				}
				if(StringUtils.isNotBlank(prjId)){
					PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
					String prjTypCd = prjBscInfoVO.getPrjTypCd();
					Integer isInsBiz = prjBscInfoVO.getIsInsBiz();
					if(!(PrjBscInfoConstant.CODE_BU_ORG_CD_XNY.equals(CurrentThreadContext.getCurrentBuOrgCd()) && !(BaseConstant.IS_YESNO_YES == isInsBiz))){
						InsRouteBscInfoVO insRouteBscInfoVO = this.insRouteBscInfoService.searchListByPrjId(Long.valueOf(prjId));
						List<InsRoutePrpsFeeVO> insRoutePrpsFeeVOList = new ArrayList<InsRoutePrpsFeeVO>();
						if(insRouteBscInfoVO != null){
							insRoutePrpsFeeVOList = insRouteBscInfoVO.getInsRoutePrpsFeeVOList();
						}
						List<InsRoutePrdInfoVO> insRoutePrdInfoVOList = insRouteBscInfoVO.getInsRoutePrdInfoVOList();
						Double mediationFeeAmtSum = 0d;
						if(CollectionUtils.isNotEmpty(insRoutePrdInfoVOList)){
							for (InsRoutePrdInfoVO insRoutePrdInfoVO : insRoutePrdInfoVOList) {
								mediationFeeAmtSum += DecimalUtils.convertFenToYuan(insRoutePrdInfoVO.getMediationFeeAmt()*insRoutePrdInfoVO.getPrdQty());

							}
						}
						Double actAmt = 0d;
						boolean fee76 = false;
						for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : list) {
							String feeTypCd = prjQuatPrpsCfgDVO.getFeeTypCd();
							if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76.equals(feeTypCd)){
								fee76 = true;
								prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
								if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
									prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
									prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
									prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
								}else{
									prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
									prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
								}
								prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
								prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
							}
							if(StringUtils.isNotEmpty(feeTypCd)
									&& (PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(feeTypCd)
									|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)
									|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_63.equals(feeTypCd)
									|| PrjQuatPrpsFeeConstant.FEE_TYP_CD_64.equals(feeTypCd))){
								if(CollectionUtils.isNotEmpty(insRoutePrpsFeeVOList)){
									for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
										if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_01.equals(insRoutePrpsFeeVO.getFeeTypCd())){
											actAmt = insRouteBscInfoVO.getContAmt() - insRoutePrpsFeeVO.getFeeAmt();
										}
									}
									for (InsRoutePrpsFeeVO insRoutePrpsFeeVO : insRoutePrpsFeeVOList) {
										if(feeTypCd.equals(insRoutePrpsFeeVO.getFeeTypCd())){
											if(null!=insRoutePrpsFeeVO.getFeeAmt()){
												prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.convertFenToYuan(insRoutePrpsFeeVO.getFeeAmt().longValue()));
											}
											if(null!=insRoutePrpsFeeVO.getFeePct() && insRoutePrpsFeeVO.getFeePct().doubleValue() != 0){
												prjQuatPrpsCfgDVO.setFeePct(insRoutePrpsFeeVO.getFeePct());
											}
											if(null!=insRoutePrpsFeeVO.getCntWayCd()){
												prjQuatPrpsCfgDVO.setCntWayCd(insRoutePrpsFeeVO.getCntWayCd());
											}
											if(null!=insRoutePrpsFeeVO.getIsFixedAmt()){
												prjQuatPrpsCfgDVO.setIsFixedAmt(insRoutePrpsFeeVO.getIsFixedAmt());
											}
											prjQuatPrpsCfgDVO.setIsRoute(BaseConstant.IS_YESNO_YES);
											if(PrjQuatPrpsFeeConstant.FEE_TYP_CD_02.equals(feeTypCd)){
												if(StringUtils.isNotBlank(insRoutePrpsFeeVO.getCalBaseCd())
														&& !((insRoutePrpsFeeVO.getCalBaseCd()).equals(prjQuatPrpsCfgDVO.getCalBaseCd()))){
													if(PrjQuatPrpsConstant.CODE_CAL_BASE_CONTRACT.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
														if(null!=insRoutePrpsFeeVO.getFeeAmt()){
															prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),insRouteBscInfoVO.getContAmt(),10)*100);
														}
													}else if(PrjQuatPrpsConstant.CODE_CAL_BASE_FINANCING.equals(prjQuatPrpsCfgDVO.getCalBaseCd())){
														prjQuatPrpsCfgDVO.setFeePct(DecimalUtils.div(insRoutePrpsFeeVO.getFeeAmt(),actAmt,10)*100);
													}
												}
											}
										}
									}
								}
							}
						}
						if(mediationFeeAmtSum != 0 && !fee76){
							PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO = new PrjQuatPrpsCfgDVO();
							prjQuatPrpsCfgDVO.setPrpsCfgId(list.get(0).getPrpsCfgId());
							prjQuatPrpsCfgDVO.setFeeTypCd(PrjQuatPrpsFeeConstant.FEE_TYP_CD_76);
							prjQuatPrpsCfgDVO.setFeeTypCdNm("调节费");
							prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_YES);
							prjQuatPrpsCfgDVO.setIsAllowChgNm("是");
							prjQuatPrpsCfgDVO.setIsSysDef(BaseConstant.IS_YESNO_NO);
							prjQuatPrpsCfgDVO.setIsSysDefNm("否");
							prjQuatPrpsCfgDVO.setFixedAmt(mediationFeeAmtSum);
							if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_ESCJYD.equals(prjTypCd) || PrjBscInfoConstant.PRJ_TYP_CD_OWNJYD.equals(prjTypCd)){
								prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT);
								prjQuatPrpsCfgDVO.setCntWayCdNm("计入合同额");
								prjQuatPrpsCfgDVO.setIsAllowChg(BaseConstant.IS_YESNO_NO);
							}else{
								prjQuatPrpsCfgDVO.setCntWayCd(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_OTH);
								prjQuatPrpsCfgDVO.setCntWayCdNm("其他费用");
							}
							prjQuatPrpsCfgDVO.setIsFixedAmt(BaseConstant.IS_YESNO_YES);
							prjQuatPrpsCfgDVO.setIsFixedAmtNm("是");
							list.add(prjQuatPrpsCfgDVO);
						}
					}
				}
			}
			ListPageVO<PrjQuatPrpsCfgDVO> listPage = new ListPageVO<PrjQuatPrpsCfgDVO>(feeList, pager.getTotalCount());
			logger.info("查询数据完成:page:{}",JSON.toJSONString(page));
			return listPage;
		
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getPrjQuatContFeeDetailById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getPrjQuatContFeeDetailById(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String prpsCfgId = request.getParameter("prpsCfgId");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		   PrjQuatPrpsCfgDQueryCondition qc = new PrjQuatPrpsCfgDQueryCondition();
		    page.setEveryPage(Integer.MAX_VALUE);//最大数据量
			qc.setPrpsCfgId(Long.valueOf(prpsCfgId));
			page.setCondition(qc);
			Pager pager = this.prjQuatPrpsCfgDService.searchListPage(page);
			List<PrjQuatPrpsCfgDVO> feeList = new ArrayList<PrjQuatPrpsCfgDVO>();
			List<PrjQuatPrpsCfgDVO> list = (List<PrjQuatPrpsCfgDVO>) pager.getResultList();
			if(CollectionUtils.isNotEmpty(list)){
				for (int i=0;i<list.size();i++) {
					PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO  = list.get(i);
					//处理费用金额
					if(null!=prjQuatPrpsCfgDVO.getFixedAmt()){
						prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.div(prjQuatPrpsCfgDVO.getFixedAmt(), 100));
					}
					if(prjQuatPrpsCfgDVO.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_CONT)){
						feeList.add(prjQuatPrpsCfgDVO);
					}
					
				}
			}
			ListPageVO<PrjQuatPrpsCfgDVO> listPage = new ListPageVO<PrjQuatPrpsCfgDVO>(feeList, pager.getTotalCount());
			logger.info("根据id获取报价方案费用项详细信息page:{}",JSON.toJSONString(page));
			return listPage;
	}
}

